﻿using System.Reflection;
using System.Text;

namespace Api.Core.Common.Cache
{
    public static class CacheKey
    {
        public static string GetCacheKey(MethodInfo methodInfo, object[] args)
        {
            StringBuilder cacheKey = new StringBuilder();
            cacheKey.Append(methodInfo.DeclaringType.Name).Append($"_{methodInfo.Name}");
            foreach (var item in args)
            {
                var parms = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                parms = parms.Replace('"', ' ').Replace(":", "");
                cacheKey.Append($"_{parms}");
            }
            return cacheKey.ToString();
        }
    }
}
